<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "document".
 *
 * @property string $id 文档ID
 * @property string $uid 用户ID
 * @property string $name 标识
 * @property string $title 标题
 * @property string $category_id 所属分类
 * @property int $group_id 所属分组
 * @property string $description 描述
 * @property string $root 根节点
 * @property string $pid 所属ID
 * @property int $model_id 内容模型ID
 * @property int $type 内容类型
 * @property int $position 推荐位
 * @property string $link_id 外链
 * @property string $cover_id 封面
 * @property int $display 可见性
 * @property string $deadline 截至时间
 * @property int $attach 附件数量
 * @property string $view 浏览量
 * @property string $comment 评论数
 * @property string $extend 扩展统计字段
 * @property int $level 优先级
 * @property string $create_time 创建时间
 * @property string $update_time 更新时间
 * @property int $status 数据状态
 */
class Document extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'document';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'category_id', 'group_id', 'root', 'pid', 'model_id', 'type', 'position', 'link_id', 'cover_id', 'display', 'deadline', 'attach', 'view', 'comment', 'extend', 'level', 'create_time', 'update_time', 'status'], 'integer'],
            [['uid','category_id', 'group_id','title','level','view','link_id'], 'required'],
            [['title'],'unique'],
            [['name'], 'string', 'max' => 40],
            [['title'], 'string', 'max' => 80],
            [['description'], 'string', 'max' => 140],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'uid' => '作者',
            'name' => '标识',
            'title' => '标题',
            'category_id' => '分类',
            'group_id' => '分组',
            'description' => 'Description',
            'root' => 'Root',
            'pid' => 'Pid',
            'model_id' => 'Model ID',
            'type' => 'Type',
            'position' => 'Position',
            'link_id' => 'Link ID',
            'cover_id' => 'Cover ID',
            'display' => 'Display',
            'deadline' => 'Deadline',
            'attach' => 'Attach',
            'view' => '浏览',
            'comment' => 'Comment',
            'extend' => 'Extend',
            'level' => 'Level',
            'create_time' => '创建日期',
            'update_time' => '更新日期',
            'status' => '状态',
        ];
    }
    
    //分类 关联
    public function getCategory0(){
        
        return $this->hasOne(Category::className(), ['id'=>'category_id']);
    }
    
    public function getUid0(){
        
        return $this->hasOne(user::className(), ['id'=>'uid']);
    }
    
}
